package com.yonyou.crm.common.rest.util;

import java.util.HashMap;
import java.util.Map;

import com.yonyou.crm.common.rest.constant.CrmCodeConstant;
import com.yonyou.crm.common.rest.constant.HttpKeyConstant;

public class ResponseUtil{
	
	/*****************成功返回*****************/
	
	/**
	 * 响应成功，无返回数据，无提示信息
	 * @return
	 */
	public static Object getObject() {
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.Code, CrmCodeConstant.Success);
		resultMap.put(HttpKeyConstant.Message, "");
		return resultMap;
	}
	
	/**
	 * 响应成功，无返回数据，有提示信息
	 * @param msg
	 * @return
	 */
	public static Object getObject(String msg) {
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.Code, CrmCodeConstant.Success);
		resultMap.put(HttpKeyConstant.Message, msg);
		return resultMap;
	}
	
	/**
	 * 响应成功，有响应数据，无提示信息
	 * @param data
	 * @return
	 */
	public static Object getObject(Object data) {
				
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.ResponseRootKey, data);
		resultMap.put(HttpKeyConstant.Code, CrmCodeConstant.Success);
		resultMap.put(HttpKeyConstant.Message, "");
		return resultMap;
	}
	
	/**
	 * 响应成功，有响应数据，有提示信息
	 * @param data
	 * @param msg
	 * @return
	 */
	public static Object getObject(Object data, String msg) {
				
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.ResponseRootKey, data);
		resultMap.put(HttpKeyConstant.Code, CrmCodeConstant.Success);
		resultMap.put(HttpKeyConstant.Message, msg);
		return resultMap;
	}
	
	/*****************失败返回*****************/
	
	/**
	 * 自定义code，无返回数据，有提示信息
	 * @param code
	 * @param msg
	 * @return
	 */
	public static Object getObject(String code, String msg) {
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.Code, code);
		resultMap.put(HttpKeyConstant.Message, msg);
		return resultMap;
	}
	
	/**
	 * 自定义code，有返回数据，有提示信息
	 * @param data
	 * @param code
	 * @param msg
	 * @return
	 */
	public static Object getObject(Object data, String code, String msg) {
				
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put(HttpKeyConstant.ResponseRootKey, data);
		resultMap.put(HttpKeyConstant.Code, code);
		resultMap.put(HttpKeyConstant.Message, msg);
		return resultMap;
	}

}
